﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Management.Automation;
using PowerOBIProvider;
using System.Collections.ObjectModel;
using PowerOBIProvider.OBI;
using PowerOBIPRovider.OBIWebReference;

namespace PowerOBIProvider.Cmdlts
{
    [Cmdlet(VerbsCommon.Get,"SubjectAreaProperty")]
    public class GetSubjectAreaPropertyCmdlt :BaseOBICmdlt
    {


        private string saName = null;
        [Parameter(Mandatory = true, Position = 1)]
        [ValidateNotNullOrEmpty]
        public string SAName
        {
            get
            {
                return saName;
            }
            set
            {
                saName = value;
            }
        }
        private string drive = null;

        
        private bool includeTables = true;
        [Parameter(Mandatory = false, Position = 2)]
        public SwitchParameter IncludeTables
        {
            get
            {
                return includeTables;
            }
            set
            {
                includeTables = value;
            }
        }
        
        private bool includeTablesAndColumns = false;
        [Parameter(Mandatory = false, Position = 3)]
        public SwitchParameter IncludeTablesAndColumns
        {
            get
            {
                return includeTablesAndColumns;
            }
            set
            {
                includeTablesAndColumns = value;
            }
        }

        private bool minimum = false;
        [Parameter(Mandatory = false, Position = 4)]
        public SwitchParameter Minimum
        {
            get
            {
                return minimum;
            }
            set
            {
                minimum = value;
            }
        }
        [Parameter(Mandatory = false, Position = 5)]
        [ValidateNotNullOrEmpty]
        public string Drive
        {
            get
            {
                return drive;
            }
            set
            {
                drive = value;
            }
        }
        protected override void ProcessRecord()
        {
            PSOBIDriveInfo obiDrive = null;
            if (drive == null)
            {
                obiDrive = GetOBIDrive(SessionState.Path.CurrentLocation);
            }
            else
            {
                obiDrive = SessionState.Drive.Get(drive) as PSOBIDriveInfo;
            }
            try
            {
                SASubjectAreaDetails saDetails = SASubjectAreaDetails.IncludeTables; //default action
                if (IncludeTablesAndColumns)
                    saDetails = SASubjectAreaDetails.IncludeTablesAndColumns;
                else if (Minimum)
                    saDetails = SASubjectAreaDetails.Minimum;


                SASubjectArea subjectArea = obiDrive.ObiWSClient.GetSubjectAreaDetails(saName, saDetails);
                WriteObject(subjectArea);
                

            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "0", ErrorCategory.OperationStopped, null));
            }
        }

    }
}
